package model.bean;

import java.io.IOException;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

import model.util.AcEliManager;


@ManagedBean(name="linkBean")
@SessionScoped
public class LinkBean {
	public String menuLeft = "";
	
	
	public String getMenuLeft() {
		return menuLeft;
	}


	public void setMenuLeft(String menuLeft) {
		this.menuLeft = menuLeft;
	}

	String db="acc";
// create link danh mục tài khoản
	public String linkMenuAccount() throws IOException{
		FacesContext f = FacesContext.getCurrentInstance();
		String path = f.getExternalContext().getRequestContextPath();
//		HttpSession ss = (HttpSession) f.getExternalContext().getSession(true);
//		AcEliManager eli = (AcEliManager) ss.getAttribute("accessDB");
//		if(eli!=null){
//			db=eli.getDatabaseName();
//		}
//		if (ss.getAttribute("Employee") != null) {
			f.getExternalContext().redirect(path+
					"/acc/menuAccount");
//			menuLeft = path + "/generalAccounting/menuAccount.xhtml";
//		} else {
//			f.getExternalContext().redirect(
//					"/" + eli.getDatabaseName() + "/acc/home");
//		}
		return "";
	}
	
	// create link điều chỉnh chứng từ
	
	public String linkAdjustmentVoucher()throws IOException{
		FacesContext f = FacesContext.getCurrentInstance();
		String path = f.getExternalContext().getRequestContextPath();
//		HttpSession ss = (HttpSession) f.getExternalContext().getSession(true);
//		AcEliManager eli = (AcEliManager) ss.getAttribute("accessDB");
//		if (ss.getAttribute("Employee") != null) {
//			f.getExternalContext().redirect(
//					"/" + eli.getDatabaseName() + "/acc/adjustmentVoucher");
//			menuLeft = path + "/generalAccounting/adjustmentVoucher.xhtml";
//		} else {
//			f.getExternalContext().redirect(
//					"/" + eli.getDatabaseName() + "/acc/home");
//		}
		f.getExternalContext().redirect(
				path+ "/acc/adjustmentVoucher");
		
		return "";
	}
	
	// create link danh mục khách hàng
	public String linkMenuCustomer()throws IOException{
		FacesContext f = FacesContext.getCurrentInstance();
		String path = f.getExternalContext().getRequestContextPath();
//		HttpSession ss = (HttpSession) f.getExternalContext().getSession(true);
//		AcEliManager eli = (AcEliManager) ss.getAttribute("accessDB");
//		if (ss.getAttribute("Employee") != null) {
//			f.getExternalContext().redirect(
//					"/" + eli.getDatabaseName() + "/acc/menuCustomer");
//			menuLeft = path + "/receivableAccounting/menuCustomer.xhtml";
//		} else {
//			f.getExternalContext().redirect(
//					"/" + eli.getDatabaseName() + "/acc/home");
//		}
		f.getExternalContext().redirect(
				path + "/acc/menuCustomer");
		return "";
	}
	// create link các khoản phải thu
	public String linkReceivales()throws IOException{
		FacesContext f = FacesContext.getCurrentInstance();
		String path = f.getExternalContext().getRequestContextPath();
//		HttpSession ss = (HttpSession) f.getExternalContext().getSession(true);
//		AcEliManager eli = (AcEliManager) ss.getAttribute("accessDB");
//		if (ss.getAttribute("Employee") != null) {
//			f.getExternalContext().redirect(
//					"/" + eli.getDatabaseName() + "/acc/receivables");
//			menuLeft = path + "/receivableAccounting/receivables.xhtml";
//		} else {
//			f.getExternalContext().redirect(
//					"/" + eli.getDatabaseName() + "/acc/home");
//		}
		f.getExternalContext().redirect(
				path + "/acc/receivables");
		return "";
	}
	// create link thanh toán và áp chứng từ
	public String linkPaymentAndVouchers()throws IOException{
		FacesContext f = FacesContext.getCurrentInstance();
		String path = f.getExternalContext().getRequestContextPath();
//		HttpSession ss = (HttpSession) f.getExternalContext().getSession(true);
//		AcEliManager eli = (AcEliManager) ss.getAttribute("accessDB");
//		if (ss.getAttribute("Employee") != null) {
//			f.getExternalContext().redirect(
//					"/" + eli.getDatabaseName() + "/acc/paymentAndVoucher");
//			menuLeft = path + "/receivableAccounting/paymentAndVoucher.xhtml";
//		} else {
//			f.getExternalContext().redirect(
//					"/" + eli.getDatabaseName() + "/acc/home");
//		}
		f.getExternalContext().redirect(
				path + "/acc/paymentAndVoucher");
		return "";
	}
	// create link thanh toán trả trước
	public String linkPrePayment() throws IOException{
		FacesContext f = FacesContext.getCurrentInstance();
		String path = f.getExternalContext().getRequestContextPath();
//		HttpSession ss = (HttpSession) f.getExternalContext().getSession(true);
//		AcEliManager eli = (AcEliManager) ss.getAttribute("accessDB");
//		if (ss.getAttribute("Employee") != null) {
//			f.getExternalContext().redirect(
//					"/" + eli.getDatabaseName() + "/acc/prepayment");
//			menuLeft = path + "/receivableAccounting/prepayment.xhtml";
//		} else {
//			f.getExternalContext().redirect(
//					"/" + eli.getDatabaseName() + "/acc/home");
//		}
		f.getExternalContext().redirect(
				path + "/acc/prepayment");
		return "";
	}
	
	// create link xử lý nhiều chứng từ
	public String linkProcessVouchers() throws IOException{
		FacesContext f = FacesContext.getCurrentInstance();
		String path = f.getExternalContext().getRequestContextPath();
//		HttpSession ss = (HttpSession) f.getExternalContext().getSession(true);
//		AcEliManager eli = (AcEliManager) ss.getAttribute("accessDB");
//		if (ss.getAttribute("Employee") != null) {
//			f.getExternalContext().redirect(
//					"/" + eli.getDatabaseName() + "/acc/processVouchers");
//			menuLeft = path + "/receivableAccounting/processVouchers.xhtml";
//		} else {
//			f.getExternalContext().redirect(
//					"/" + eli.getDatabaseName() + "/acc/home");
//		}
		f.getExternalContext().redirect(
				path + "/acc/processVouchers");
		return "";
	}
	// create link chi tiết hạch toán phải thu
	public String linkDetailAccountingReceivable() throws IOException{
		FacesContext f = FacesContext.getCurrentInstance();
		String path = f.getExternalContext().getRequestContextPath();
//		HttpSession ss = (HttpSession) f.getExternalContext().getSession(true);
//		AcEliManager eli = (AcEliManager) ss.getAttribute("accessDB");
//		if (ss.getAttribute("Employee") != null) {
//			f.getExternalContext().redirect(
//					"/" + eli.getDatabaseName() + "/acc/detailAccountingReceivable");
//			menuLeft = path + "/receivableAccounting/detailAccountingReceivable.xhtml";
//		} else {
//			f.getExternalContext().redirect(
//					"/" + eli.getDatabaseName() + "/acc/home");
//		}
		f.getExternalContext().redirect(
				path + "/acc/detailAccountingReceivable");
		return "";
	}
	
	// create link số dư tài khoản 131-138
	public String linkBalanceAccount() throws IOException{
		FacesContext f = FacesContext.getCurrentInstance();
		String path = f.getExternalContext().getRequestContextPath();
//		HttpSession ss = (HttpSession) f.getExternalContext().getSession(true);
//		AcEliManager eli = (AcEliManager) ss.getAttribute("accessDB");
//		if (ss.getAttribute("Employee") != null) {
//			f.getExternalContext().redirect(
//					"/" + eli.getDatabaseName() + "/acc/accountBalance");
//			menuLeft = path + "/receivableAccounting/accountBalance.xhtml";
//		} else {
//			f.getExternalContext().redirect(
//					"/" + eli.getDatabaseName() + "/acc/home");
//		}
		f.getExternalContext().redirect(
				path + "/acc/accountBalance");
		return "";
	}
	// create link bảng kê hóa đơn giá trị gia tăng
	public String linkStatisticVAT() throws IOException{
		FacesContext f = FacesContext.getCurrentInstance();
		String path = f.getExternalContext().getRequestContextPath();
//		HttpSession ss = (HttpSession) f.getExternalContext().getSession(true);
//		AcEliManager eli = (AcEliManager) ss.getAttribute("accessDB");
//		if (ss.getAttribute("Employee") != null) {
//			f.getExternalContext().redirect(
//					"/" + eli.getDatabaseName() + "/acc/statisticVAT");
//			menuLeft = path + "/receivableAccounting/statisticVAT.xhtml";
//		} else {
//			f.getExternalContext().redirect(
//					"/" + eli.getDatabaseName() + "/acc/home");
//		}
		f.getExternalContext().redirect(
				path + "/acc/statisticVAT");
		return "";
	}
}
